<?php

namespace App\Http\Controllers\Backend\Report;

use App\ConstDir\ErrorConst;
use App\Http\Controllers\Backend\BaseController;
use App\Repository\Repositories\Interfaces\ReportTypeRepository;
use Illuminate\Http\Request;
use Prettus\Repository\Criteria\RequestCriteria;

/**
 * 举报类型管理
 *
 * @package App\Http\Controllers\Report
 */
class ReportTypeController extends BaseController
{
	/**
	 * @var ReportTypeRepository
	 */
	protected $report_repo;


	public function __construct(ReportTypeRepository $report_type_repo, Request $request)
	{
		$this->report_type_repo = $report_type_repo;
	}

	public function index()
	{
		$report_type = $this->report_type_repo->paginate($this->perPage);

		return $this->success(ErrorConst::SUCCESS_CODE, $report_type, true);
	}
	public function store(Request $request){
		$data = [
			"name" => $request->post('name'),
			"content" => $request->post('content'),
			"status" => 0,
		];
		$ret = $this->report_type_repo->create($data);
		if ($ret) {
			return $this->success(ErrorConst::SUCCESS_CODE, ErrorConst::SUCCESS_CODE_MSG);
		} else {
			return $this->error(ErrorConst::FAILED_CODE);
		}

	}


	public function delete($id)
	{
		$ret = $this->report_type_repo->delete($id);

		if ($ret) {
			return $this->success(ErrorConst::SUCCESS_CODE, ErrorConst::SUCCESS_CODE_MSG);
		} else {
			return $this->error(ErrorConst::FAILED_CODE);
		}
	}
}
